import { createRouter, createWebHistory } from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Shouye.vue'
import AdminLogin from '../views/AdminLogin.vue'
import ForgotPassword from '../views/ForgotPassword.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/forgot-password',
      name: 'ForgotPassword',
      component: ForgotPassword
    },
    {
      path: '/adminLogin',
      name: 'Admin',
      component: AdminLogin
    },
    {
      path: '/admin',
      component: () => import('../views/adminHome/home.vue'),
      redirect: '/admin/welcome',
      children: [
        {
          path: 'welcome',
          name: 'AdminWelcome',
          component: () => import('../views/adminHome/Welcome.vue')
        },
        {
          path: 'community-list',
          name: 'CommunityList',
          component: () => import('../views/adminHome/CommunityList.vue')
        },
        {
          path: 'community-members',
          name: 'CommunityMembers',
          component: () => import('../views/adminHome/CommunityMembers.vue')
        },
        {
          path: 'add-member',
          name: 'AddMember',
          component: () => import('../views/adminHome/AddMember.vue')
        }
      ]
    },
    {
      path: '/home',
      name: 'Home',
      component: Home,
      redirect: '/home/intro',
      children: [
        {
          path: 'intro',
          name: 'Intro',
          component: () => import('../views/home/Intro.vue')
        },
        {
          path: 'members',
          name: 'Members',
          component: () => import('../views/home/Members.vue')
        },
        {
          path: 'elders',
          name: 'Elders',
          component: () => import('../views/home/Elders.vue')
        },
        {
          path: 'warnings',
          name: 'Warnings',
          component: () => import('../views/home/Warnings.vue')
        },
        {
          path: 'health',
          name: 'Health',
          component: () => import('../views/home/Health.vue')
        },
        {
          path: 'health-detail/:dataId',
          name: 'HealthDetail',
          component: () => import('../views/home/HealthDetail.vue')
        },
        {
          path: 'outing',
          name: 'Outing',
          component: () => import('../views/home/Outing.vue')
        }
      ]
    }
  ]
})

// router.beforeEach((to, from, next) => {
//   if (to.matched.some(record => record.meta.requiresAuth)) {
//     // 检查是否已登录
//     if (!localStorage.getItem('token')) {
//       next({
//         path: '/login',
//         query: { redirect: to.fullPath }
//       })
//     } else {
//       next()
//     }
//   } else {
//     next()
//   }
// })

export default router